Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

262
Visualizações
Why isn't JavaScript and HTML letting me use the word 'clear' as a name of the function?

I have the following code in which when you enter a number in the input and press the button multiply by 3, it gives the result. And when you press clear, it should clear the result (the empty p tag). I have given the value clear() to the clear button and have also used clear() to call the function in JavaScript, but when I run the code and then try the Clear button, it doesn't work. Here is the code:

function multiplyBy3(){
document.getElementById('result').innerHTML = document.getElementById('xx').value*3;
}
function clear(){
document.getElementById('result').style.display = "none";
}
<label for="number">Enter a number:</label>
<input id="xx" type="number">
<p id="result"></p><br>
<button onclick="multiplyBy3();">Multiply by 3</button>
<button onclick="clear();">Clear</button>




Replaced 'clear' by 'rr':

However, when I replace the word clear by another word, it does work. I replaced clear by rr in the following code and it's working perfectly fine. Here is the modified code:

function multiplyBy3(){
document.getElementById('result').innerHTML = document.getElementById('xx').value*3;
}
function rr(){
document.getElementById('result').style.display = "none";
}
<label for="number">Enter a number:</label>
<input id="xx" type="number">
<p id="result"></p><br>
<button onclick="multiplyBy3();">Multiply by 3</button>
<button onclick="rr();">Clear</button>



I also checked the Reserved words/keywords but it isn't one of them. Can anyone tell me why it isn't working?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda